//
//  UserViewModel.swift
//  MVVMDemo2
//
//  Created by 李煜 on 2024/6/7.
//

import UIKit
import Alamofire
class UserViewModel {
    var didReceiveUsers: (([User]?, AFError?) -> Void)?
    func fetchUsers() {
        let url = "https://example.com/api/users" //接口地址
        AF.request(url,method: .post).responseDecodable(of: [User].self) { response in
            switch response.result {
                case .success(let users):
                    self.didReceiveUsers?(users, nil)
                case let .failure(e):
                    self.didReceiveUsers?(nil, e)

            }
        }
    }
}
